using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class CharacterFootStep : MonoBehaviour
{
	private AudioSource audios;

	private CharacterSystem character;

	private float delay;

	public AudioClip[] FoodSteps;

	public float Delay = 3f;

	private void Start()
	{
		character = base.gameObject.GetComponent<CharacterSystem>();
		audios = base.gameObject.GetComponent<AudioSource>();
	}

	private void PlaySound()
	{
		if ((bool)character && ((character.Motor != null && character.Motor.grounded) || character.Motor == null) && FoodSteps.Length > 0)
		{
			audios.PlayOneShot(FoodSteps[Random.Range(0, FoodSteps.Length)]);
		}
	}

	private void Update()
	{
		if ((bool)character)
		{
			if (character.enabled && character.IsAlive && ((character.Motor != null && character.Motor.grounded) || character.Motor == null) && delay >= Delay)
			{
				PlaySound();
				delay = 0f;
			}
			if (delay < Delay)
			{
				delay += character.MoveVelocity.magnitude * Time.deltaTime;
			}
		}
	}
}
